package com.cl.pattern.state;

/**
 * 上下文
 *
 * 维护着所有状态
 */
public class Context {

    /**
     * 状态1
     */
    public final static State STATE1 = new ConcreteState1();
    /**
     * 状态2
     */
    public final static State STATE2 = new ConcreteState2();

    /**
     * 当前状态
     */
    private State currentState;

    /**
     * 获得当前状态
     * @return
     */
    public State getCurrentState() {
        return currentState;
    }

    /**
     * 设置当前状态
     * @param currentState
     */
    public void setCurrentState(State currentState) {
        this.currentState = currentState;
        this.currentState.setContext(this);
    }

    public void handle1() {
        this.currentState.operation1();
    }

    public void handle2() {
        this.currentState.operation2();
    }

}